package com.xiaocz.hblsubstitutedriving.adapter;

import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.xiaocz.common.widgets.recycler.RecyclerViewAdapter;
import com.xiaocz.hblsubstitutedriving.R;
import com.xiaocz.hblsubstitutedriving.model.Announcement;


/**
 * Author:  xiaocz.
 * Date:    2018/05.04.
 * Descr:  公告
 */
public class AnnouncementListAdapter extends RecyclerViewAdapter<Announcement> {

    public AnnouncementListAdapter(AdapterListener<Announcement> adapterListener) {
        super(adapterListener);
    }

    @Override
    protected int getItemViewType(int position, Announcement data) {
        return R.layout.item_order_list;
    }

    @Override
    protected ViewHolder<Announcement> getViewHolder(View view, int viewType) {
        return new InfoTypeViewHolder(view);
    }

    private static class InfoTypeViewHolder extends ViewHolder<Announcement> {

        private TextView tvTitle, tv_order_state, tv_start_address, tv_end_address;

        public InfoTypeViewHolder(View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.info_title);
            tv_order_state = itemView.findViewById(R.id.tv_order_state);
            tv_start_address = itemView.findViewById(R.id.tv_start_address);
            tv_end_address = itemView.findViewById(R.id.tv_end_address);
        }

        @Override
        protected void onBind(Announcement data, int position) {
            tvTitle.setText(data.getTitle());
            int textColor = ContextCompat.getColor(mContext, R.color.colorAccent);
            switch (data.getMessagetype()) {
                case 2:
                    textColor = ContextCompat.getColor(mContext, R.color.red_500);
                    break;
                case 3:
                    textColor = ContextCompat.getColor(mContext, R.color.textColorSecond);
                    break;
                case 4:
                    textColor = ContextCompat.getColor(mContext, R.color.textColorSecond);
                    break;
                case 5:
                    textColor = ContextCompat.getColor(mContext, R.color.textColorOrange);
                    break;
                case 6:
                    textColor = ContextCompat.getColor(mContext, R.color.textColorSecond);
                    break;
            }
            tv_order_state.setTextColor(textColor);
            tv_order_state.setText(data.getMessagetypename());
            tv_start_address.setText(data.getUser_name());
            tv_end_address.setText(data.getCreatetime());
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }
}